package Queue;

public class MyQueue {
    static class Node{
        public int val;
        public Node next;

        public Node(int val) {
            this.val = val;
        }
    }
    public Node head;
    public Node tail;
    public int useSize;


    public void offer(int val){
        Node node = new Node(val);
        if (head==null){
            head=node;
            tail=node;
        }else {
            useSize++;
            tail.next=node;
            tail=tail.next;

        }

    }

    public int poll(){
        if (head==null){
            return -1;
        }
        int oldval=head.val;
        if (head.next==null){
            head = tail = null;
        }else {
            head=head.next;
        }
        return oldval;
    }
     public int peek(){
         if (head==null){
             return -1;
         }
         return head.val;
     }
     public int size(){
       return useSize;
     }

}
